github.com/GGP1/kure@v0.8.4/commands/config/argon2/test/test_test.go (about)

     1  package test
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestTest(t *testing.T) {
    12  	cases := []struct {
    13  		desc       string
    14  		iterations uint32
    15  		memory     uint32
    16  		threads    uint8
    17  	}{
    18  		{
    19  			desc:       "Test 1",
    20  			iterations: 1,
    21  			memory:     400000,
    22  			threads:    uint8(runtime.NumCPU()),
    23  		},
    24  		{
    25  			desc:       "Test 2",
    26  			iterations: 15,
    27  			memory:     3000,
    28  			threads:    uint8(runtime.NumCPU()),
    29  		},
    30  		{
    31  			desc:       "Test 3",
    32  			iterations: 2,
    33  			memory:     716500,
    34  			threads:    uint8(runtime.NumCPU() - 1),
    35  		},
    36  	}
    37  
    38  	cmd := NewCmd()
    39  
    40  	for _, tc := range cases {
    41  		t.Run(tc.desc, func(t *testing.T) {
    42  			f := cmd.Flags()
    43  			f.Set("iterations", fmt.Sprintf("%d", tc.iterations))
    44  			f.Set("memory", fmt.Sprintf("%d", tc.memory))
    45  			f.Set("threads", fmt.Sprintf("%d", tc.threads))
    46  
    47  			err := cmd.Execute()
    48  			assert.NoError(t, err)
    49  		})
    50  	}
    51  }
    52  
    53  func TestTestInvalid(t *testing.T) {
    54  	cases := []struct {
    55  		desc       string
    56  		iterations string
    57  		memory     string
    58  		threads    string
    59  	}{
    60  		{
    61  			desc:       "Invalid iterations",
    62  			iterations: "0",
    63  			memory:     "1",
    64  			threads:    "1",
    65  		},
    66  		{
    67  			desc:       "Invalid memory",
    68  			iterations: "1",
    69  			memory:     "0",
    70  			threads:    "1",
    71  		},
    72  		{
    73  			desc:       "Invalid threads",
    74  			iterations: "1",
    75  			memory:     "1",
    76  			threads:    "0",
    77  		},
    78  	}
    79  
    80  	for _, tc := range cases {
    81  		t.Run(tc.desc, func(t *testing.T) {
    82  			cmd := NewCmd()
    83  			f := cmd.Flags()
    84  			f.Set("iterations", tc.iterations)
    85  			f.Set("memory", tc.memory)
    86  			f.Set("threads", tc.threads)
    87  
    88  			err := cmd.RunE(nil, nil)
    89  			assert.Error(t, err)
    90  		})
    91  	}
    92  }
    93  
    94  func TestPostRun(t *testing.T) {
    95  	NewCmd().PostRun(nil, nil)
    96  }