forked from toolshed/abra
		
	
		
			
				
	
	
		
			63 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package app_test
 | |
| 
 | |
| import (
 | |
| 	"testing"
 | |
| 
 | |
| 	appPkg "coopcloud.tech/abra/pkg/app"
 | |
| 	testPkg "coopcloud.tech/abra/pkg/test"
 | |
| 	stack "coopcloud.tech/abra/pkg/upstream/stack"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| )
 | |
| 
 | |
| func TestGetTimeoutFromLabel(t *testing.T) {
 | |
| 	testPkg.MkServerAppRecipe()
 | |
| 	defer testPkg.RmServerAppRecipe()
 | |
| 
 | |
| 	tests := []struct {
 | |
| 		configuredTimeout string
 | |
| 		expectedTimeout   int
 | |
| 	}{
 | |
| 		{"0", 0},
 | |
| 		{"DOESNTEXIST", 0}, // NOTE(d1): test when missing from .env
 | |
| 		{"80", 80},
 | |
| 		{"120", 120},
 | |
| 	}
 | |
| 
 | |
| 	for _, test := range tests {
 | |
| 		app, err := appPkg.GetApp(testPkg.ExpectedAppFiles, testPkg.AppName)
 | |
| 		if err != nil {
 | |
| 			t.Fatal(err)
 | |
| 		}
 | |
| 
 | |
| 		if test.configuredTimeout != "DOESNTEXIST" {
 | |
| 			app.Env["TIMEOUT"] = test.configuredTimeout
 | |
| 		}
 | |
| 
 | |
| 		composeFiles, err := app.Recipe.GetComposeFiles(app.Env)
 | |
| 		if err != nil {
 | |
| 			t.Fatal(err)
 | |
| 		}
 | |
| 
 | |
| 		deployOpts := stack.Deploy{
 | |
| 			Composefiles: composeFiles,
 | |
| 			Namespace:    app.StackName(),
 | |
| 			Prune:        false,
 | |
| 			ResolveImage: stack.ResolveImageAlways,
 | |
| 			Detach:       false,
 | |
| 		}
 | |
| 
 | |
| 		compose, err := appPkg.GetAppComposeConfig(app.Name, deployOpts, app.Env)
 | |
| 		if err != nil {
 | |
| 			t.Fatal(err)
 | |
| 		}
 | |
| 
 | |
| 		timeout, err := appPkg.GetTimeoutFromLabel(compose, app.StackName())
 | |
| 		if err != nil {
 | |
| 			t.Fatal(err)
 | |
| 		}
 | |
| 
 | |
| 		assert.Equal(t, timeout, test.expectedTimeout)
 | |
| 	}
 | |
| }
 |