-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements the manual token input test case
It starts the GUI in the manual token input scenario The GUI must then apply the token obtained from the environment This asserts that previously and newly registered distros are affected
- Loading branch information
1 parent
6089462
commit cfcae09
Showing
1 changed file
with
87 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,87 @@ | ||
package endtoend_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
wsl "github.com/ubuntu/gowsl" | ||
) | ||
|
||
func TestManualTokenInput(t *testing.T) { | ||
type whenToken int | ||
const ( | ||
never whenToken = iota | ||
beforeDistroRegistration | ||
afterDistroRegistration | ||
) | ||
|
||
// Let's be lazy and don't fall into the risk of changing the function name without updating the places where its name is used. | ||
currentFuncName := getCurrentFuncName() | ||
|
||
testCases := map[string]struct { | ||
whenToken whenToken | ||
overrideTokenEnv string | ||
|
||
wantAttached bool | ||
}{ | ||
"Success when applying pro token before registration": {whenToken: beforeDistroRegistration, wantAttached: true}, | ||
"Success when applying pro token after registration": {whenToken: afterDistroRegistration, wantAttached: true}, | ||
|
||
"Error with invalid token": {whenToken: afterDistroRegistration, overrideTokenEnv: fmt.Sprintf("%s=%s", proTokenEnv, "CJd8MMN8wXSWsv7wJT8c8dDK")}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
tc := tc | ||
t.Run(name, func(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
testSetup(t) | ||
|
||
// Either runs the ubuntupro app before... | ||
if tc.whenToken == beforeDistroRegistration { | ||
cleanup := startAgent(t, ctx, currentFuncName, tc.overrideTokenEnv) | ||
defer cleanup() | ||
} | ||
|
||
// Distro setup | ||
name := registerFromTestImage(t, ctx) | ||
d := wsl.NewDistro(ctx, name) | ||
|
||
defer logWslProServiceJournal(t, ctx, d) | ||
|
||
out, err := d.Command(ctx, "exit 0").CombinedOutput() | ||
require.NoErrorf(t, err, "Setup: could not wake distro up: %v. %s", err, out) | ||
|
||
// ... or after registration, but never both. | ||
if tc.whenToken == afterDistroRegistration { | ||
// the exact time between registering the distro and running the app cannot be determined, so there is a chance | ||
// of this starting the app before registration completes. | ||
time.Sleep(5 * time.Second) | ||
cleanup := startAgent(t, ctx, currentFuncName, tc.overrideTokenEnv) | ||
defer cleanup() | ||
} | ||
|
||
time.Sleep(5 * time.Second) | ||
out, err = d.Command(ctx, "exit 0").CombinedOutput() | ||
require.NoErrorf(t, err, "Setup: could not wake distro up: %v. %s", err, out) | ||
|
||
if !tc.wantAttached { | ||
attached, err := distroIsProAttached(t, d) | ||
require.NoError(t, err, "could not determine if distro is attached") | ||
require.False(t, attached, "distro should not have been Pro attached") | ||
return | ||
} | ||
|
||
require.Eventually(t, func() bool { | ||
attached, err := distroIsProAttached(t, d) | ||
if err != nil { | ||
t.Logf("could not determine if distro is attached: %v", err) | ||
} | ||
return attached | ||
}, 30*time.Second, time.Second, "distro should have been Pro attached") | ||
}) | ||
} | ||
} |