github.com/TaceyWong/ctools@v0.1.1-0.20201221084458-4d7a8190b2ac/pkg/open/open_test.go (about)

     1  package open
     2  
     3  import "testing"
     4  
     5  func TestRun(t *testing.T) {
     6  	// shouldn't error
     7  	input := "https://google.com/"
     8  	err := Run(input)
     9  	if err != nil {
    10  		t.Errorf("open.Run(\"%s\") threw an error: %s", input, err)
    11  	}
    12  
    13  	// should error
    14  	input = "xxxxxxxxxxxxxxx"
    15  	err = Run(input)
    16  	if err == nil {
    17  		t.Errorf("Run(\"%s\") did not throw an error as expected", input)
    18  	}
    19  }
    20  
    21  func TestStart(t *testing.T) {
    22  	// shouldn't error
    23  	input := "https://google.com/"
    24  	err := Start(input)
    25  	if err != nil {
    26  		t.Errorf("open.Start(\"%s\") threw an error: %s", input, err)
    27  	}
    28  
    29  	// shouldn't error
    30  	input = "xxxxxxxxxxxxxxx"
    31  	err = Start(input)
    32  	if err != nil {
    33  		t.Errorf("open.Start(\"%s\") shouldn't even fail on invalid input: %s", input, err)
    34  	}
    35  }
    36  
    37  func TestRunWith(t *testing.T) {
    38  	// shouldn't error
    39  	input := "https://google.com/"
    40  	app := "firefox"
    41  	err := RunWith(input, app)
    42  	if err != nil {
    43  		t.Errorf("open.RunWith(\"%s\", \"%s\") threw an error: %s", input, app, err)
    44  	}
    45  
    46  	// should error
    47  	app = "xxxxxxxxxxxxxxx"
    48  	err = RunWith(input, app)
    49  	if err == nil {
    50  		t.Errorf("RunWith(\"%s\", \"%s\") did not throw an error as expected", input, app)
    51  	}
    52  }
    53  
    54  func TestStartWith(t *testing.T) {
    55  	// shouldn't error
    56  	input := "https://google.com/"
    57  	app := "firefox"
    58  	err := StartWith(input, app)
    59  	if err != nil {
    60  		t.Errorf("open.StartWith(\"%s\", \"%s\") threw an error: %s", input, app, err)
    61  	}
    62  
    63  	// shouldn't error
    64  	input = "[<Invalid URL>]"
    65  	err = StartWith(input, app)
    66  	if err != nil {
    67  		t.Errorf("StartWith(\"%s\", \"%s\") shouldn't even fail on invalid input: %s", input, app, err)
    68  	}
    69  
    70  }