mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 14:57:49 +00:00
cmd/tailscale/cli: move earlier shell test to its own files
(I should've done this to start with.) Updates tailscale/corp#7515 Change-Id: I7fb88cf95772790fd415ecf28fc52bde95507641 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
9e70daad6f
commit
b5ac9172fd
@ -11,7 +11,6 @@
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -1157,50 +1156,3 @@ func TestUpWorthWarning(t *testing.T) {
|
||||
t.Errorf("want false for other misc errors")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeConfigMutations(t *testing.T) {
|
||||
// Stateful mutations, starting from an empty config.
|
||||
type step struct {
|
||||
command []string // serve args
|
||||
reset bool // if true, reset all ServeConfig state
|
||||
want *ipn.ServeConfig
|
||||
wantErr string
|
||||
line int // line number of addStep call, for error messages
|
||||
}
|
||||
var steps []step
|
||||
add := func(s step) {
|
||||
_, _, s.line, _ = runtime.Caller(1)
|
||||
steps = append(steps, s)
|
||||
}
|
||||
add(step{reset: true})
|
||||
add(step{
|
||||
want: nil,
|
||||
})
|
||||
var current *ipn.ServeConfig
|
||||
for i, st := range steps {
|
||||
t.Logf("Executing step #%d (line %v) ... ", i, st.line)
|
||||
if st.reset {
|
||||
t.Logf("(resetting state)")
|
||||
current = nil
|
||||
}
|
||||
newState, err := applyServeMutation(current, st.command)
|
||||
var gotErr string
|
||||
if err != nil {
|
||||
gotErr = err.Error()
|
||||
}
|
||||
if gotErr != st.wantErr {
|
||||
t.Fatalf("[%d] %v: got error %q, want %q", i, st.command, gotErr, st.wantErr)
|
||||
}
|
||||
if !reflect.DeepEqual(newState, st.want) {
|
||||
t.Fatalf("[%d] %v: bad state. got:\n%s\n\nwant:\n%s\n",
|
||||
i, st.command, asJSON(newState), asJSON(st.want))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func applyServeMutation(current *ipn.ServeConfig, command []string) (*ipn.ServeConfig, error) {
|
||||
if len(command) == 0 {
|
||||
return current, nil
|
||||
}
|
||||
panic("TODO") // in cli/serve.go, not here in tests
|
||||
}
|
||||
|
14
cmd/tailscale/cli/serve.go
Normal file
14
cmd/tailscale/cli/serve.go
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cli
|
||||
|
||||
import "tailscale.com/ipn"
|
||||
|
||||
func applyServeMutation(current *ipn.ServeConfig, command []string) (*ipn.ServeConfig, error) {
|
||||
if len(command) == 0 {
|
||||
return current, nil
|
||||
}
|
||||
panic("TODO")
|
||||
}
|
53
cmd/tailscale/cli/serve_test.go
Normal file
53
cmd/tailscale/cli/serve_test.go
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/ipn"
|
||||
)
|
||||
|
||||
func TestServeConfigMutations(t *testing.T) {
|
||||
// Stateful mutations, starting from an empty config.
|
||||
type step struct {
|
||||
command []string // serve args
|
||||
reset bool // if true, reset all ServeConfig state
|
||||
want *ipn.ServeConfig
|
||||
wantErr string
|
||||
line int // line number of addStep call, for error messages
|
||||
}
|
||||
var steps []step
|
||||
add := func(s step) {
|
||||
_, _, s.line, _ = runtime.Caller(1)
|
||||
steps = append(steps, s)
|
||||
}
|
||||
add(step{reset: true})
|
||||
add(step{
|
||||
want: nil,
|
||||
})
|
||||
var current *ipn.ServeConfig
|
||||
for i, st := range steps {
|
||||
t.Logf("Executing step #%d (line %v) ... ", i, st.line)
|
||||
if st.reset {
|
||||
t.Logf("(resetting state)")
|
||||
current = nil
|
||||
}
|
||||
newState, err := applyServeMutation(current, st.command)
|
||||
var gotErr string
|
||||
if err != nil {
|
||||
gotErr = err.Error()
|
||||
}
|
||||
if gotErr != st.wantErr {
|
||||
t.Fatalf("[%d] %v: got error %q, want %q", i, st.command, gotErr, st.wantErr)
|
||||
}
|
||||
if !reflect.DeepEqual(newState, st.want) {
|
||||
t.Fatalf("[%d] %v: bad state. got:\n%s\n\nwant:\n%s\n",
|
||||
i, st.command, asJSON(newState), asJSON(st.want))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user