-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for store_unmanaged.lua #16
- Loading branch information
1 parent
c55c864
commit b70c5ce
Showing
4 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
config interface 'loopback' | ||
option ifname 'lo' | ||
option proto 'static' | ||
option ipaddr '127.0.0.1' | ||
option netmask '255.0.0.0' | ||
|
||
config globals 'globals' | ||
option ula_prefix 'fd8e:f40a:6701::/48' | ||
|
||
config interface 'lan' | ||
option ifname 'eth0.1' | ||
option type 'bridge' | ||
option proto 'dhcp' | ||
option ip6assign '60' | ||
option force_link '0' | ||
|
||
config interface 'wan' | ||
option ifname 'eth0.2' | ||
option proto 'none' | ||
|
||
config interface 'wlan0' | ||
option ifname 'wlan0' | ||
option ipaddr '172.27.254.251/16' | ||
option proto 'static' | ||
|
||
config interface 'wlan1' | ||
option ifname 'wlan1' | ||
option ipaddr '172.27.254.252/16' | ||
option proto 'static' | ||
|
||
config switch | ||
option name 'switch0' | ||
option reset '1' | ||
option enable_vlan '1' | ||
|
||
config switch_vlan | ||
option device 'switch0' | ||
option vlan '1' | ||
option ports '0t 2 3 4 5' | ||
|
||
config switch_vlan | ||
option device 'switch0' | ||
option vlan '2' | ||
option ports '0t 1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
config system | ||
option hostname 'OpenWrt' | ||
option timezone 'UTC' | ||
|
||
config timeserver 'ntp' | ||
list server '0.openwrt.pool.ntp.org' | ||
list server '1.openwrt.pool.ntp.org' | ||
list server '2.openwrt.pool.ntp.org' | ||
list server '3.openwrt.pool.ntp.org' | ||
option enabled '1' | ||
option enable_server '0' | ||
|
||
config led 'led_usb1' | ||
option name 'USB1' | ||
option sysfs 'tp-link:green:usb1' | ||
option trigger 'usbdev' | ||
option dev '1-1.1' | ||
option interval '50' | ||
|
||
config led 'led_usb2' | ||
option name 'USB2' | ||
option sysfs 'tp-link:green:usb2' | ||
option trigger 'usbdev' | ||
option dev '1-1.2' | ||
option interval '50' | ||
|
||
config led 'led_wlan2g' | ||
option name 'WLAN2G' | ||
option sysfs 'tp-link:blue:wlan2g' | ||
option trigger 'phy0tpt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
require('os') | ||
require('io') | ||
local luaunit = require('luaunit') | ||
local store_unmanaged = assert(loadfile("../files/store_unmanaged.lua")) | ||
local default_blocks = "system.ntp " .. | ||
"system.@led " .. | ||
"network.loopback " .. | ||
"network.globals " .. | ||
"network.lan " .. | ||
"network.wan " .. | ||
"network.@switch " .. | ||
"network.@switch_vlan" | ||
local string = string | ||
local prefix = './unmanaged/' | ||
assertNotNil = luaunit.assertNotNil | ||
assertNil = luaunit.assertNil | ||
|
||
local function _clean() | ||
os.remove(prefix .. 'network') | ||
os.remove(prefix .. 'system') | ||
end | ||
|
||
TestStoreUnmanaged = {} | ||
|
||
TestStoreUnmanaged.setUp = _clean | ||
TestStoreUnmanaged.tearDown = _clean | ||
|
||
function TestStoreUnmanaged.test_empty() | ||
store_unmanaged('--test=1') | ||
assertNil(io.open(prefix .. 'network')) | ||
assertNil(io.open(prefix .. 'system')) | ||
end | ||
|
||
function TestStoreUnmanaged.test_default() | ||
store_unmanaged('--test=1', '-o=' .. default_blocks) | ||
-- ensure network config file has been created correctly | ||
local file = io.open(prefix .. 'network') | ||
assertNotNil(file) | ||
local contents = file:read('*all') | ||
assertNotNil(string.find(contents, "config interface 'loopback'")) | ||
assertNotNil(string.find(contents, "option ipaddr '127.0.0.1'")) | ||
assertNotNil(string.find(contents, "option ula_prefix 'fd8e:f40a:6701::/48'")) | ||
assertNotNil(string.find(contents, "config interface 'wan'")) | ||
assertNotNil(string.find(contents, "config switch")) | ||
assertNotNil(string.find(contents, "option vlan '2'")) | ||
assertNotNil(string.find(contents, "option vlan '1'")) | ||
assertNil(string.find(contents, "config interface 'wlan0'")) | ||
assertNil(string.find(contents, "config interface 'wlan1'")) | ||
-- ensure system config file exists | ||
local file = io.open(prefix .. 'system') | ||
assertNotNil(file) | ||
local contents = file:read('*all') | ||
assertNotNil(string.find(contents, "list server '1.openwrt.pool.ntp.org'")) | ||
assertNotNil(string.find(contents, "config led 'led_usb1'")) | ||
assertNotNil(string.find(contents, "config led 'led_usb2'")) | ||
assertNotNil(string.find(contents, "config led 'led_wlan2g'")) | ||
assertNil(string.find(contents, "option hostname 'OpenWrt'")) | ||
end | ||
|
||
function TestStoreUnmanaged.test_specific_name() | ||
store_unmanaged('--test=1', '-o="system.ntp"') | ||
local file = io.open(prefix .. 'system') | ||
assertNotNil(file) | ||
local contents = file:read('*all') | ||
assertNotNil(file) | ||
assertNil(string.find(contents, "config led 'led_usb1'")) | ||
assertNil(string.find(contents, "option hostname 'OpenWrt'")) | ||
assertNotNil(string.find(contents, "list server '1.openwrt.pool.ntp.org'")) | ||
end | ||
|
||
function TestStoreUnmanaged.test_specific_type() | ||
store_unmanaged('--test=1', '-o="system.@led"') | ||
local file = io.open(prefix .. 'system') | ||
assertNotNil(file) | ||
local contents = file:read('*all') | ||
assertNotNil(file) | ||
assertNotNil(string.find(contents, "config led 'led_usb1'")) | ||
assertNotNil(string.find(contents, "config led 'led_usb2'")) | ||
assertNotNil(string.find(contents, "config led 'led_wlan2g'")) | ||
assertNil(string.find(contents, "option hostname 'OpenWrt'")) | ||
assertNil(string.find(contents, "list server '1.openwrt.pool.ntp.org'")) | ||
end | ||
|
||
function TestStoreUnmanaged.test_unrecognized_config_option() | ||
store_unmanaged('--test=1', '-o="network.vpn"') | ||
local file = io.open(prefix .. 'network') | ||
assertNotNil(file) | ||
local contents = file:read('*all') | ||
assertNil(string.find(contents, "vpn")) | ||
end | ||
|
||
function TestStoreUnmanaged.test_unrecognized_config_type() | ||
store_unmanaged('--test=1', '-o="network.@vpn"') | ||
local file = io.open(prefix .. 'network') | ||
assertNotNil(file) | ||
local contents = file:read('*all') | ||
assertNil(string.find(contents, "vpn")) | ||
end | ||
|
||
function test_unrecognized_config() | ||
store_unmanaged('--test=1', '-o="totally.@wrong"') | ||
assertNil(io.open(prefix .. 'totally')) | ||
end | ||
|
||
os.exit(luaunit.LuaUnit.run()) |
Empty file.