ソースを参照

test(apt): Add resolver to test quicker

- Dns resolution quicker for kitchen-test
- Add resolver on all tests

Signed-off-by: Jeremy MAURO <jeremy.mauro@gmail.com>
Jeremy MAURO 2 年 前
コミット
239f212d40

+ 32 - 4
base.lock.json

@@ -1,12 +1,17 @@
 {
-  "revision_id": "93f85e5d20ae75fbc3ad6f74528843b9e1ce3f6485a737fd7b7c5155fdd665f2",
+  "revision_id": "b92a7491d2c38309f5d2e58c2965de75df2eafa3050372c9da85e799be8ef1ae",
   "name": "base",
   "run_list": [
     "recipe[workstation::default]"
   ],
   "named_run_lists": {
     "git": [
+      "recipe[workstation::_resolver]",
       "recipe[workstation::_git]"
+    ],
+    "apt": [
+      "recipe[workstation::_resolver]",
+      "recipe[workstation::_apt]"
     ]
   },
   "included_policy_locks": [
@@ -59,6 +64,18 @@
         "version": "1.1.0"
       }
     },
+    "resolver": {
+      "version": "4.0.3",
+      "identifier": "b1dbb867c55732ab3b8c018eba2ad3bf769ace25",
+      "dotted_decimal_identifier": "50062655939237682.48197693525113386.232819282071077",
+      "cache_key": "resolver-4a815ef9db05a6d95f353f2b08a891737cad96b4",
+      "origin": "https://github.com/jmauro/resolver",
+      "source_options": {
+        "git": "https://github.com/jmauro/resolver",
+        "revision": "4a815ef9db05a6d95f353f2b08a891737cad96b4",
+        "branch": "atomic_update"
+      }
+    },
     "seven_zip": {
       "version": "4.2.2",
       "identifier": "a97443e4baa8bb56ef7aef7e085c8985fafa8423",
@@ -72,14 +89,14 @@
     },
     "workstation": {
       "version": "0.1.0",
-      "identifier": "686828b9dc4db37278242bac4fe9a331c1842b27",
-      "dotted_decimal_identifier": "29387921704111539.32220244091883497.179434095389479",
+      "identifier": "5af0ee98d96222da8a1ddf5bb00bbc22d69ce543",
+      "dotted_decimal_identifier": "25597655461224994.61513405828935691.206857815516483",
       "source": "cookbooks/workstation",
       "cache_key": null,
       "scm_info": {
         "scm": "git",
         "remote": null,
-        "revision": "77f5ec5510d8a5ebd742da8081fdd5cd32de6f53",
+        "revision": "3db3835a0ebe7b50790215491857c37a0cd33435",
         "working_tree_clean": false,
         "published": false,
         "synchronized_remote_branches": [
@@ -122,6 +139,10 @@
         "github",
         "= 1.1.0"
       ],
+      [
+        "resolver",
+        ">= 0.0.0"
+      ],
       [
         "seven_zip",
         "= 4.2.2"
@@ -152,6 +173,9 @@
       ],
       "github (1.1.0)": [
 
+      ],
+      "resolver (4.0.3)": [
+
       ],
       "seven_zip (4.2.2)": [
 
@@ -168,6 +192,10 @@
         [
           "github",
           ">= 0.0.0"
+        ],
+        [
+          "resolver",
+          ">= 0.0.0"
         ]
       ]
     }

+ 7 - 0
base.rb

@@ -17,13 +17,20 @@ run_list [
 
 # Kitchen-test suite
 named_run_list :git, [
+  'workstation::_resolver',
   'workstation::_git',
 ]
 
+named_run_list :apt, [
+  'workstation::_resolver',
+  'workstation::_apt',
+]
+
 # Specify a custom source for a single cookbook:
 # cookbook 'example_cookbook', path: '../cookbooks/example_cookbook'
 cookbook 'etckeeper', git: 'https://github.com/jmauro/etckeeper-cookbook', branch: 'master-next'
 cookbook 'git', git: 'https://github.com/jmauro/git', branch: 'config_file_scope'
+cookbook 'resolver', git: 'https://github.com/jmauro/resolver', branch: 'atomic_update'
 
 # Global attributes
 default['my_workstation']['default_user']['jeremy'] = {

+ 1 - 0
cookbooks/workstation/metadata.rb

@@ -14,6 +14,7 @@ chef_version '>= 16.0'
 depends 'etckeeper'
 depends 'git'
 depends 'github'
+depends 'resolver'
 
 # The `source_url` points to the development repository for this cookbook.  A
 # `View Source` link will be displayed on this cookbook's page when uploaded to

+ 20 - 0
cookbooks/workstation/recipes/_resolver.rb

@@ -0,0 +1,20 @@
+#
+# Cookbook:: workstation
+# Recipe:: _resolver
+#
+# Copyright:: 2022, The Authors, All Rights Reserved.
+
+resolver_config '/etc/resolv.conf' do
+  nameservers [
+    '192.168.1.39',
+    '8.8.8.8',
+  ]
+  search [
+    'xcom.lan',
+    'test.lan',
+  ]
+  options(
+    'timeout' => 2,
+  )
+  atomic_update false
+end

+ 29 - 0
cookbooks/workstation/spec/unit/recipes/_resolver_spec.rb

@@ -0,0 +1,29 @@
+#
+# Cookbook:: workstation
+# Spec:: _resolver
+#
+# Copyright:: 2022, The Authors, All Rights Reserved.
+
+require 'spec_helper'
+
+describe 'workstation::_resolver' do
+  context 'When all attributes are default, on Ubuntu 20.04' do
+    # for a complete list of available platforms and versions see:
+    # https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md
+    platform 'ubuntu', '20.04'
+
+    it 'converges successfully' do
+      expect { chef_run }.to_not raise_error
+    end
+  end
+
+  context 'When all attributes are default, on CentOS 8' do
+    # for a complete list of available platforms and versions see:
+    # https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md
+    platform 'centos', '8'
+
+    it 'converges successfully' do
+      expect { chef_run }.to_not raise_error
+    end
+  end
+end

+ 16 - 0
cookbooks/workstation/test/integration/default/_resolver_test.rb

@@ -0,0 +1,16 @@
+# Chef InSpec test for recipe workstation::_resolver
+
+# The Chef InSpec reference, with examples and extensive documentation, can be
+# found at https://docs.chef.io/inspec/resources/
+
+unless os.windows?
+  # This is an example test, replace with your own test.
+  describe user('root'), :skip do
+    it { should exist }
+  end
+end
+
+# This is an example test, replace it with your own test.
+describe port(80), :skip do
+  it { should_not be_listening }
+end

+ 9 - 0
kitchen.yml

@@ -58,3 +58,12 @@ suites:
         - podman start chef-latest
       post_destroy:
         - podman volume prune -f
+  - name: workstation-apt
+    provisioner:
+      named_run_list: 'apt'
+    lifecycle:
+      pre_create:
+        - podman create --name chef-latest --replace docker.io/chef/chef:latest sh
+        - podman start chef-latest
+      post_destroy:
+        - podman volume prune -f