Skip to content

Commit

Permalink
Update banner_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrNJ authored Jan 30, 2025
1 parent e13b714 commit 0218a5f
Showing 1 changed file with 122 additions and 120 deletions.
242 changes: 122 additions & 120 deletions feature/system/tests/system_base_test/banner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package system_base_test

import (
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"strings"
"testing"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"strings"
"testing"
)

// TestMotdBanner verifies that the MOTD configuration paths can be read,
Expand All @@ -30,64 +30,65 @@ import (
// telemetry_path:/system/state/motd-banner
func TestMotdBanner(t *testing.T) {

testCases := []struct {
description string
banner string
}{
{"Empty String", ""},
{"Single Character", "x"},
{"Short String", "Warning Text"},
{"Long String", "WARNING : Unauthorized access to this system is forbidden and will be prosecuted by law. By accessing this system, you agree that your actions may be monitored if unauthorized usage is suspected."},
}

dut := ondatra.DUT(t, "dut")
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
config := gnmi.OC().System().MotdBanner()
state := gnmi.OC().System().MotdBanner()

gnmi.Replace(t, dut, config.Config(), testCase.banner)

t.Run("Get MOTD Config", func(t *testing.T) {
if testCase.banner == "" {
if gnmi.LookupConfig(t, dut, config.Config()).IsPresent() {
t.Errorf("MOTD Banner not empty")
} else {
t.Logf("No response for the path is expected as the config is empty")
}
} else {
configGot := gnmi.Get(t, dut, config.Config())
configGot = strings.TrimSpace(configGot)
if configGot != testCase.banner {
t.Errorf("Config MOTD Banner: got %s, want %s", configGot, testCase.banner)
}
}
})

t.Run("Get MOTD Telemetry", func(t *testing.T) {
if testCase.banner == "" {
if gnmi.LookupConfig(t, dut, config.Config()).IsPresent() {
t.Errorf("MOTD Telemetry Banner not empty")
} else {
t.Logf("No response for the path is expected as the config is empty")
}
} else {
stateGot := gnmi.Get(t, dut, state.State())
stateGot = strings.TrimSpace(stateGot)
if stateGot != testCase.banner {
t.Errorf("Telemetry MOTD Banner: got %v, want %s", stateGot, testCase.banner)
}
}
})

t.Run("Delete MOTD", func(t *testing.T) {
gnmi.Delete(t, dut, config.Config())
if qs := gnmi.LookupConfig(t, dut, config.Config()); qs.IsPresent() == true {
t.Errorf("Delete MOTD Banner fail: got %v", qs)
}
})
})
}
testCases := []struct {
description string
banner string
}{
{"Empty String", ""},
{"Single Character", "x"},
{"Short String", "Warning Text"},
{"Long String", "WARNING : Unauthorized access to this system is forbidden and will be prosecuted by law. By accessing this system, you agree that your actions may be monitored if unauthorized usage is s

Check failure on line 40 in feature/system/tests/system_base_test/banner_test.go

View workflow job for this annotation

GitHub Actions / Static Analysis

string literal not terminated
uspected."},
}

dut := ondatra.DUT(t, "dut")
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
config := gnmi.OC().System().MotdBanner()
state := gnmi.OC().System().MotdBanner()

gnmi.Replace(t, dut, config.Config(), testCase.banner)

t.Run("Get MOTD Config", func(t *testing.T) {
if testCase.banner == "" {
if gnmi.LookupConfig(t, dut, config.Config()).IsPresent() {
t.Errorf("MOTD Banner not empty")
} else {
t.Logf("No response for the path is expected as the config is empty")
}
} else {
configGot := gnmi.Get(t, dut, config.Config())
configGot = strings.TrimSpace(configGot)
if configGot != testCase.banner {
t.Errorf("Config MOTD Banner: got %s, want %s", configGot, testCase.banner)
}
}
})

t.Run("Get MOTD Telemetry", func(t *testing.T) {
if testCase.banner == "" {
if gnmi.LookupConfig(t, dut, config.Config()).IsPresent() {
t.Errorf("MOTD Telemetry Banner not empty")
} else {
t.Logf("No response for the path is expected as the config is empty")
}
} else {
stateGot := gnmi.Get(t, dut, state.State())
stateGot = strings.TrimSpace(stateGot)
if stateGot != testCase.banner {
t.Errorf("Telemetry MOTD Banner: got %v, want %s", stateGot, testCase.banner)
}
}
})

t.Run("Delete MOTD", func(t *testing.T) {
gnmi.Delete(t, dut, config.Config())
if qs := gnmi.LookupConfig(t, dut, config.Config()); qs.IsPresent() == true {
t.Errorf("Delete MOTD Banner fail: got %v", qs)
}
})
})
}
}

// TestLoginBanner verifies that the Login Banner configuration paths can be
Expand All @@ -96,62 +97,63 @@ func TestMotdBanner(t *testing.T) {
// config_path:/system/config/login-banner
// telemetry_path:/system/state/login-banner
func TestLoginBanner(t *testing.T) {
testCases := []struct {
description string
banner string
}{
{"Empty String", ""},
{"Single Character", "x"},
{"Short String", "Warning Text"},
{"Long String", "WARNING : Unauthorized access to this system is forbidden and will be prosecuted by law. By accessing this system, you agree that your actions may be monitored if unauthorized usage is suspected."},
}

dut := ondatra.DUT(t, "dut")

for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
config := gnmi.OC().System().LoginBanner()
state := gnmi.OC().System().LoginBanner()

gnmi.Replace(t, dut, config.Config(), testCase.banner)

t.Run("Get Login Banner Config", func(t *testing.T) {
if testCase.banner == "" {
if gnmi.LookupConfig(t, dut, config.Config()).IsPresent() {
t.Errorf("Config Login Banner not empty")
} else {
t.Logf("No response for the path expected is expected as the config is empty")
}
} else {
configGot := gnmi.Get(t, dut, config.Config())
configGot = strings.TrimSpace(configGot)
if configGot != testCase.banner {
t.Errorf("Config Login Banner: got %s, want %s", configGot, testCase.banner)
}
}
})

t.Run("Get Login Banner Telemetry", func(t *testing.T) {
if testCase.banner == "" {
if gnmi.LookupConfig(t, dut, config.Config()).IsPresent() {
t.Errorf("Telemetry Login Banner not empty")
} else {
t.Logf("No response for the path is expected as the config is empty")
}
} else {
stateGot := gnmi.Get(t, dut, state.State())
stateGot = strings.TrimSpace(stateGot)
if stateGot != testCase.banner {
t.Errorf("Telemetry Login Banner: got %v, want %s", stateGot, testCase.banner)
}
}
})
t.Run("Delete Login Banner", func(t *testing.T) {
gnmi.Delete(t, dut, config.Config())
if qs := gnmi.LookupConfig(t, dut, config.Config()); qs.IsPresent() == true {
t.Errorf("Delete Login Banner fail: got %v", qs)
}
})
})
}
testCases := []struct {
description string
banner string
}{
{"Empty String", ""},
{"Single Character", "x"},
{"Short String", "Warning Text"},
{"Long String", "WARNING : Unauthorized access to this system is forbidden and will be prosecuted by law. By accessing this system, you agree that your actions may be monitored if unauthorized usage is s
uspected."},
}

dut := ondatra.DUT(t, "dut")

for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
config := gnmi.OC().System().LoginBanner()
state := gnmi.OC().System().LoginBanner()

gnmi.Replace(t, dut, config.Config(), testCase.banner)

t.Run("Get Login Banner Config", func(t *testing.T) {
if testCase.banner == "" {
if gnmi.LookupConfig(t, dut, config.Config()).IsPresent() {
t.Errorf("Config Login Banner not empty")
} else {
t.Logf("No response for the path expected is expected as the config is empty")
}
} else {
configGot := gnmi.Get(t, dut, config.Config())
configGot = strings.TrimSpace(configGot)
if configGot != testCase.banner {
t.Errorf("Config Login Banner: got %s, want %s", configGot, testCase.banner)
}
}
})

t.Run("Get Login Banner Telemetry", func(t *testing.T) {
if testCase.banner == "" {
if gnmi.LookupConfig(t, dut, config.Config()).IsPresent() {
t.Errorf("Telemetry Login Banner not empty")
} else {
t.Logf("No response for the path is expected as the config is empty")
}
} else {
stateGot := gnmi.Get(t, dut, state.State())
stateGot = strings.TrimSpace(stateGot)
if stateGot != testCase.banner {
t.Errorf("Telemetry Login Banner: got %v, want %s", stateGot, testCase.banner)
}
}
})
t.Run("Delete Login Banner", func(t *testing.T) {
gnmi.Delete(t, dut, config.Config())
if qs := gnmi.LookupConfig(t, dut, config.Config()); qs.IsPresent() == true {
t.Errorf("Delete Login Banner fail: got %v", qs)
}
})
})
}
}

0 comments on commit 0218a5f

Please sign in to comment.