github.com/in4it/ecs-deploy@v0.0.42-0.20240508120354-ed77ff16df25/api/api_test.go (about) 1 package api 2 3 import ( 4 "testing" 5 6 "github.com/in4it/ecs-deploy/service" 7 ) 8 9 func TestDeployServiceValidator(t *testing.T) { 10 // api object 11 a := API{} 12 13 // test with 2 characters 14 d := service.Deploy{ 15 Containers: []*service.DeployContainer{ 16 { 17 ContainerName: "abc", 18 }, 19 }, 20 } 21 serviceName := "ab" 22 err := a.deployServiceValidator(serviceName, d) 23 if err == nil || err.Error() != "service name needs to be at least 3 characters" { 24 t.Errorf("Servicename with 2 characters didn't get error message") 25 } 26 27 // test with 3 characters 28 d = service.Deploy{ 29 Containers: []*service.DeployContainer{ 30 { 31 ContainerName: "abc", 32 }, 33 }, 34 ServicePort: 8080, 35 } 36 serviceName = "abc" 37 err = a.deployServiceValidator(serviceName, d) 38 if err != nil { 39 t.Errorf("%v", err) 40 } 41 42 // test with wrong container name 43 serviceName = "myservice" 44 d = service.Deploy{ 45 Containers: []*service.DeployContainer{ 46 { 47 ContainerName: "ab", 48 }, 49 { 50 ContainerName: "abd", 51 }, 52 }, 53 } 54 serviceName = "abc" 55 err = a.deployServiceValidator(serviceName, d) 56 if err == nil { 57 t.Errorf("No containerName is equal to serviceName, but no error raised") 58 } 59 }