|
| 1 | +// Copyright 2020 DSR Corporation |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +//go:build !dev |
| 16 | + |
| 17 | +package validator |
| 18 | + |
| 19 | +import ( |
| 20 | + "net/url" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/stretchr/testify/require" |
| 24 | +) |
| 25 | + |
| 26 | +func TestURLLivenessCheck(t *testing.T) { |
| 27 | + negativeTests := []string{ |
| 28 | + "https://dcl-test.org", |
| 29 | + "https://httpbin.org/status/404", |
| 30 | + "https://httpbin.org/status/500", |
| 31 | + } |
| 32 | + positiveTests := []string{ |
| 33 | + "http://github.com/", // Redirects to https://github.com/ |
| 34 | + "https://httpbin.org/status/401", // Private repo |
| 35 | + "https://httpbin.org/status/403", // Unavailable for some reason |
| 36 | + } |
| 37 | + |
| 38 | + for _, testUrl := range negativeTests { |
| 39 | + u, err := url.ParseRequestURI(testUrl) |
| 40 | + require.NoError(t, err) |
| 41 | + |
| 42 | + require.False(t, _isLiveURL(u)) |
| 43 | + } |
| 44 | + |
| 45 | + for _, testUrl := range positiveTests { |
| 46 | + u, err := url.ParseRequestURI(testUrl) |
| 47 | + require.NoError(t, err) |
| 48 | + |
| 49 | + require.True(t, _isLiveURL(u)) |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments