TimothyYe / skm

A simple and powerful SSH keys manager
https://timothyye.github.io/skm
MIT License
954 stars 54 forks source link

Add CLI Test #8

Closed Bo0km4n closed 6 years ago

Bo0km4n commented 6 years ago

Hello. First of all, thanks for making a great tool. By the way, I want to add cli_test.go. Perhaps a different name might be better. This file actually execute main.go and tests its standard output.

If you give permission I would like to write this test. How about?

cli_test example

package main

import (
    "bytes"
    "fmt"
    "strings"
    "testing"
)

func TestRun_versionFlag(t *testing.T) {
    outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
    cli := &CLIoutStream: outStream, errStream: errStream
    args := strings.Split("skm -version", " ")

    status := cli.Run(args)
    if status != ExitCodeOK
        t.Errorf("ExitStatus=%d, want %d", status, ExitCodeOK)
    }

    expected := fmt.Sprintf("skm version %s", Version)
    if !strings.Contains(errStream.String(), expected)
        t.Errorf("Output=%q, want %q", errStream.String(), expected)
     }
}
TimothyYe commented 6 years ago

Hello @Bo0km4n Thank you for your suggestion, please feel free to submit your PR.

Bo0km4n commented 6 years ago

Thank you :) I'll start on now!!!