Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add trimming for TestSaveConfig config file assertion #317

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions calnex/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config

import (
"fmt"
"os"

"github.com/facebook/time/calnex/api"
"github.com/go-ini/ini"
Expand Down Expand Up @@ -242,20 +243,22 @@ func Config(target string, insecureTLS bool, cc *CalnexConfig, apply bool) error
// Save saves the Network/Calnex configs to file
func Save(target string, insecureTLS bool, cc *CalnexConfig, saveConfig string) error {
var c config
api := api.NewAPI(target, insecureTLS)

f, err := prepare(&c, api, target, cc)
calnexAPI := api.NewAPI(target, insecureTLS)

f, err := prepare(&c, calnexAPI, target, cc)
if err != nil {
return err
}

err = f.SaveTo(saveConfig)

buf, err := api.ToBuffer(f)
if err != nil {
return err
}

if err = os.WriteFile(saveConfig, buf.Bytes(), 0644); err != nil {
return err
}

return nil
}

Expand Down
293 changes: 146 additions & 147 deletions calnex/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,153 +652,152 @@ func TestJSONExport(t *testing.T) {
}

func TestSaveConfig(t *testing.T) {
expectedConfig := `[gnss]
antenna_delay = 42 ns

[measure]
device_name = %s
continuous = On
reference = Internal
meas_time = 1 days 1 hours
tie_mode = TIE + 1 PPS Alignment
ch0\used = Yes
ch1\used = No
ch2\used = No
ch3\used = No
ch4\used = No
ch5\used = No
ch6\used = Yes
ch7\used = No
ch8\used = Yes
ch9\used = Yes
ch10\used = No
ch11\used = No
ch12\used = No
ch13\used = No
ch14\used = No
ch15\used = No
ch16\used = No
ch17\used = No
ch18\used = No
ch19\used = No
ch20\used = No
ch21\used = No
ch22\used = No
ch23\used = No
ch24\used = No
ch25\used = No
ch26\used = No
ch27\used = No
ch28\used = No
ch29\used = No
ch30\used = Yes
ch31\used = No
ch32\used = No
ch33\used = No
ch34\used = No
ch35\used = No
ch36\used = No
ch37\used = No
ch38\used = No
ch39\used = No
ch40\used = No
ch6\protocol_enabled = Off
ch7\protocol_enabled = Off
ch6\virtual_channels_enabled = On
ch9\protocol_enabled = On
ch9\ptp_synce\mode\probe_type = NTP
ch10\protocol_enabled = Off
ch10\ptp_synce\mode\probe_type = Disabled
ch11\protocol_enabled = Off
ch11\ptp_synce\mode\probe_type = Disabled
ch12\protocol_enabled = Off
ch12\ptp_synce\mode\probe_type = Disabled
ch13\protocol_enabled = Off
ch13\ptp_synce\mode\probe_type = Disabled
ch14\protocol_enabled = Off
ch14\ptp_synce\mode\probe_type = Disabled
ch15\protocol_enabled = Off
ch15\ptp_synce\mode\probe_type = Disabled
ch16\protocol_enabled = Off
ch16\ptp_synce\mode\probe_type = Disabled
ch17\protocol_enabled = Off
ch17\ptp_synce\mode\probe_type = Disabled
ch18\protocol_enabled = Off
ch18\ptp_synce\mode\probe_type = Disabled
ch19\protocol_enabled = Off
ch19\ptp_synce\mode\probe_type = Disabled
ch20\protocol_enabled = Off
ch20\ptp_synce\mode\probe_type = Disabled
ch21\protocol_enabled = Off
ch21\ptp_synce\mode\probe_type = Disabled
ch22\protocol_enabled = Off
ch22\ptp_synce\mode\probe_type = Disabled
ch23\protocol_enabled = Off
ch23\ptp_synce\mode\probe_type = Disabled
ch24\protocol_enabled = Off
ch24\ptp_synce\mode\probe_type = Disabled
ch25\protocol_enabled = Off
ch25\ptp_synce\mode\probe_type = Disabled
ch26\protocol_enabled = Off
ch26\ptp_synce\mode\probe_type = Disabled
ch27\protocol_enabled = Off
ch27\ptp_synce\mode\probe_type = Disabled
ch28\protocol_enabled = Off
ch28\ptp_synce\mode\probe_type = Disabled
ch29\protocol_enabled = Off
ch29\ptp_synce\mode\probe_type = Disabled
ch30\protocol_enabled = On
ch30\ptp_synce\mode\probe_type = PTP
ch31\protocol_enabled = Off
ch31\ptp_synce\mode\probe_type = Disabled
ch32\protocol_enabled = Off
ch32\ptp_synce\mode\probe_type = Disabled
ch33\protocol_enabled = Off
ch33\ptp_synce\mode\probe_type = Disabled
ch34\protocol_enabled = Off
ch34\ptp_synce\mode\probe_type = Disabled
ch35\protocol_enabled = Off
ch35\ptp_synce\mode\probe_type = Disabled
ch36\protocol_enabled = Off
ch36\ptp_synce\mode\probe_type = Disabled
ch37\protocol_enabled = Off
ch37\ptp_synce\mode\probe_type = Disabled
ch38\protocol_enabled = Off
ch38\ptp_synce\mode\probe_type = Disabled
ch39\protocol_enabled = Off
ch39\ptp_synce\mode\probe_type = Disabled
ch40\protocol_enabled = Off
ch40\ptp_synce\mode\probe_type = Disabled
ch0\server_ip = fd00:3226:301b::1f
ch0\signal_type = 1 PPS
ch0\trig_level = 500 mV
ch0\freq = 1 Hz
ch0\suppress_steps = Yes
ch6\synce_enabled = Off
ch6\ptp_synce\ptp\dscp = 0
ch6\ptp_synce\ethernet\dhcp_v4 = Disabled
ch6\ptp_synce\ethernet\dhcp_v6 = DHCP
ch6\ptp_synce\ethernet\qsfp_fec = RS-FEC
ch7\synce_enabled = Off
ch7\ptp_synce\ptp\dscp = 0
ch7\ptp_synce\ethernet\dhcp_v4 = Disabled
ch7\ptp_synce\ethernet\dhcp_v6 = DHCP
ch9\ptp_synce\ntp\server_ip = fd00:3226:301b::3f
ch9\ptp_synce\ntp\server_ip_ipv6 = fd00:3226:301b::3f
ch9\ptp_synce\physical_packet_channel = Channel 1
ch9\ptp_synce\ntp\normalize_delays = Off
ch9\ptp_synce\ntp\protocol_level = UDP/IPv6
ch9\ptp_synce\ntp\poll_log_interval = 1 packet/16 s
ch30\ptp_synce\ptp\version = SPTP_V2.1
ch30\ptp_synce\ptp\master_ip = fd00:3016:3109:face:0:1:0
ch30\ptp_synce\ptp\master_ip_ipv6 = fd00:3016:3109:face:0:1:0
ch30\ptp_synce\physical_packet_channel = Channel 1
ch30\ptp_synce\ptp\protocol_level = UDP/IPv6
ch30\ptp_synce\ptp\log_announce_int = 1 packet/16 s
ch30\ptp_synce\ptp\log_delay_req_int = 1 packet/16 s
ch30\ptp_synce\ptp\log_sync_int = 1 packet/16 s
ch30\ptp_synce\ptp\stack_mode = Unicast
ch30\ptp_synce\ptp\domain = 0
expectedConfig := `[measure]
ch0\used=Yes
ch6\used=Yes
ch9\used=Yes
ch22\used=No
device_name=%s
continuous=On
reference=Internal
meas_time=1 days 1 hours
tie_mode=TIE + 1 PPS Alignment
ch8\used=Yes
ch6\synce_enabled=Off
ch7\synce_enabled=Off
ch6\ptp_synce\ptp\dscp=0
ch7\ptp_synce\ptp\dscp=0
ch6\ptp_synce\ethernet\dhcp_v6=DHCP
ch7\ptp_synce\ethernet\dhcp_v6=DHCP
ch6\ptp_synce\ethernet\dhcp_v4=Disabled
ch7\ptp_synce\ethernet\dhcp_v4=Disabled
ch6\ptp_synce\ethernet\qsfp_fec=RS-FEC
ch7\used=No
ch6\protocol_enabled=Off
ch7\protocol_enabled=Off
ch6\virtual_channels_enabled=On
ch0\server_ip=fd00:3226:301b::1f
ch0\trig_level=500 mV
ch0\freq=1 Hz
ch0\suppress_steps=Yes
ch0\signal_type=1 PPS
ch9\protocol_enabled=On
ch9\ptp_synce\physical_packet_channel=Channel 1
ch9\ptp_synce\ntp\server_ip=fd00:3226:301b::3f
ch9\ptp_synce\ntp\server_ip_ipv6=fd00:3226:301b::3f
ch9\ptp_synce\ntp\normalize_delays=Off
ch9\ptp_synce\ntp\protocol_level=UDP/IPv6
ch9\ptp_synce\ntp\poll_log_interval=1 packet/16 s
ch9\ptp_synce\mode\probe_type=NTP
ch30\protocol_enabled=On
ch30\ptp_synce\physical_packet_channel=Channel 1
ch30\ptp_synce\ptp\version=SPTP_V2.1
ch30\ptp_synce\ptp\master_ip=fd00:3016:3109:face:0:1:0
ch30\ptp_synce\ptp\master_ip_ipv6=fd00:3016:3109:face:0:1:0
ch30\ptp_synce\ptp\protocol_level=UDP/IPv6
ch30\ptp_synce\ptp\log_announce_int=1 packet/16 s
ch30\ptp_synce\ptp\log_delay_req_int=1 packet/16 s
ch30\ptp_synce\ptp\log_sync_int=1 packet/16 s
ch30\ptp_synce\ptp\stack_mode=Unicast
ch30\ptp_synce\ptp\domain=0
ch30\used=Yes
ch30\ptp_synce\mode\probe_type=PTP
ch33\used=No
ch33\protocol_enabled=Off
ch33\ptp_synce\mode\probe_type=Disabled
ch35\used=No
ch35\protocol_enabled=Off
ch35\ptp_synce\mode\probe_type=Disabled
ch21\used=No
ch21\protocol_enabled=Off
ch21\ptp_synce\mode\probe_type=Disabled
ch31\used=No
ch31\protocol_enabled=Off
ch31\ptp_synce\mode\probe_type=Disabled
ch20\used=No
ch20\protocol_enabled=Off
ch20\ptp_synce\mode\probe_type=Disabled
ch22\protocol_enabled=Off
ch22\ptp_synce\mode\probe_type=Disabled
ch23\used=No
ch23\protocol_enabled=Off
ch23\ptp_synce\mode\probe_type=Disabled
ch32\used=No
ch32\protocol_enabled=Off
ch32\ptp_synce\mode\probe_type=Disabled
ch38\used=No
ch38\protocol_enabled=Off
ch38\ptp_synce\mode\probe_type=Disabled
ch40\used=No
ch40\protocol_enabled=Off
ch40\ptp_synce\mode\probe_type=Disabled
ch10\used=No
ch10\protocol_enabled=Off
ch10\ptp_synce\mode\probe_type=Disabled
ch16\used=No
ch16\protocol_enabled=Off
ch16\ptp_synce\mode\probe_type=Disabled
ch11\used=No
ch11\protocol_enabled=Off
ch11\ptp_synce\mode\probe_type=Disabled
ch12\used=No
ch12\protocol_enabled=Off
ch12\ptp_synce\mode\probe_type=Disabled
ch3\used=No
ch19\used=No
ch19\protocol_enabled=Off
ch19\ptp_synce\mode\probe_type=Disabled
ch26\used=No
ch26\protocol_enabled=Off
ch26\ptp_synce\mode\probe_type=Disabled
ch34\used=No
ch34\protocol_enabled=Off
ch34\ptp_synce\mode\probe_type=Disabled
ch4\used=No
ch18\used=No
ch18\protocol_enabled=Off
ch18\ptp_synce\mode\probe_type=Disabled
ch13\used=No
ch13\protocol_enabled=Off
ch13\ptp_synce\mode\probe_type=Disabled
ch17\used=No
ch17\protocol_enabled=Off
ch17\ptp_synce\mode\probe_type=Disabled
ch36\used=No
ch36\protocol_enabled=Off
ch36\ptp_synce\mode\probe_type=Disabled
ch37\used=No
ch37\protocol_enabled=Off
ch37\ptp_synce\mode\probe_type=Disabled
ch15\used=No
ch15\protocol_enabled=Off
ch15\ptp_synce\mode\probe_type=Disabled
ch29\used=No
ch29\protocol_enabled=Off
ch29\ptp_synce\mode\probe_type=Disabled
ch14\used=No
ch14\protocol_enabled=Off
ch14\ptp_synce\mode\probe_type=Disabled
ch25\used=No
ch25\protocol_enabled=Off
ch25\ptp_synce\mode\probe_type=Disabled
ch27\used=No
ch27\protocol_enabled=Off
ch27\ptp_synce\mode\probe_type=Disabled
ch28\used=No
ch28\protocol_enabled=Off
ch28\ptp_synce\mode\probe_type=Disabled
ch39\used=No
ch39\protocol_enabled=Off
ch39\ptp_synce\mode\probe_type=Disabled
ch1\used=No
ch2\used=No
ch24\used=No
ch24\protocol_enabled=Off
ch24\ptp_synce\mode\probe_type=Disabled
ch5\used=No
[gnss]
antenna_delay=42 ns
`

ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter,
Expand Down