Skip to content

Commit

Permalink
Merge pull request #1880 from Automattic/fix/lando-domain
Browse files Browse the repository at this point in the history
fix(dev-env): use correct domain for environments
  • Loading branch information
sjinks authored Jun 17, 2024
2 parents 02f3cdd + 2fb56c3 commit 87c6646
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
15 changes: 9 additions & 6 deletions __tests__/commands/dev-env-sync-sql.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { replace } from '@automattic/vip-search-replace';
import fs from 'fs';
import Lando from 'lando';
import { PassThrough } from 'stream';

import { DevEnvImportSQLCommand } from '../../src/commands/dev-env-import-sql';
Expand Down Expand Up @@ -77,12 +78,14 @@ describe( 'commands/DevEnvSyncSQLCommand', () => {
},
};

const lando = new Lando( { domain: 'vipdev.lndo.site' } );

describe( '.generateExport', () => {
it( 'should create an instance of ExportSQLCommand and run', async () => {
const mockExport = jest.spyOn( ExportSQLCommand.prototype, 'run' );
mockExport.mockResolvedValue();

const cmd = new DevEnvSyncSQLCommand( app, env, 'test-slug' );
const cmd = new DevEnvSyncSQLCommand( app, env, 'test-slug', lando );
await cmd.generateExport();

expect( mockExport ).toHaveBeenCalled();
Expand All @@ -91,7 +94,7 @@ describe( 'commands/DevEnvSyncSQLCommand', () => {

describe( 'generateSearchReplaceMap', () => {
it( 'should return a map of search-replace values', () => {
const cmd = new DevEnvSyncSQLCommand( app, env, 'test-slug' );
const cmd = new DevEnvSyncSQLCommand( app, env, 'test-slug', lando );
cmd.slug = 'test-slug';
cmd.siteUrls = [ 'test.go-vip.com' ];
cmd.generateSearchReplaceMap();
Expand All @@ -100,7 +103,7 @@ describe( 'commands/DevEnvSyncSQLCommand', () => {
} );

it( 'should return a map of search-replace values for multisite', () => {
const cmd = new DevEnvSyncSQLCommand( app, msEnv, 'test-slug' );
const cmd = new DevEnvSyncSQLCommand( app, msEnv, 'test-slug', lando );
cmd.slug = 'test-slug';
cmd.siteUrls = [ 'test.go-vip.com', 'subsite.com' ];
cmd.generateSearchReplaceMap();
Expand All @@ -114,7 +117,7 @@ describe( 'commands/DevEnvSyncSQLCommand', () => {

describe( '.runSearchReplace', () => {
it( 'should run search-replace operation on the SQL file', async () => {
const cmd = new DevEnvSyncSQLCommand( app, env, 'test-slug' );
const cmd = new DevEnvSyncSQLCommand( app, env, 'test-slug', lando );
cmd.searchReplaceMap = { 'test.go-vip.com': 'test-slug.vipdev.lndo.site' };
cmd.slug = 'test-slug';

Expand All @@ -131,15 +134,15 @@ describe( 'commands/DevEnvSyncSQLCommand', () => {
const mockImport = jest.spyOn( DevEnvImportSQLCommand.prototype, 'run' );
mockImport.mockResolvedValue();

const cmd = new DevEnvSyncSQLCommand( app, env, 'test-slug' );
const cmd = new DevEnvSyncSQLCommand( app, env, 'test-slug', lando );
await cmd.runImport();

expect( mockImport ).toHaveBeenCalled();
} );
} );

describe( '.run', () => {
const syncCommand = new DevEnvSyncSQLCommand( app, env, 'test-slug' );
const syncCommand = new DevEnvSyncSQLCommand( app, env, 'test-slug', lando );
const exportSpy = jest.spyOn( syncCommand, 'generateExport' );
const generateSearchReplaceMapSpy = jest.spyOn( syncCommand, 'generateSearchReplaceMap' );
const searchReplaceSpy = jest.spyOn( syncCommand, 'runSearchReplace' );
Expand Down
2 changes: 1 addition & 1 deletion src/bin/vip-dev-env-sync-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ command( {
throw new UserError( 'Environment needs to be started first' );
}

const cmd = new DevEnvSyncSQLCommand( app, env, slug, trackerFn );
const cmd = new DevEnvSyncSQLCommand( app, env, slug, lando, trackerFn );
// TODO: There's a function called handleCLIException for dev-env that handles exceptions but DevEnvSyncSQLCommand has its own implementation.
// We should probably use handleCLIException instead?
const didCommandRun = await cmd.run();
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev-env-import-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class DevEnvImportSQLCommand {
throw new UserError( 'Environment needs to be started first' );
}

const expectedDomain = `${ this.slug }.vipdev.lndo.site`;
const expectedDomain = `${ this.slug }.${ lando.config.domain }`;
await validateSQL( resolvedPath, {
isImport: false,
skipChecks: [],
Expand Down
7 changes: 5 additions & 2 deletions src/commands/dev-env-sync-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class DevEnvSyncSQLCommand {
app;
env;
slug;
lando;
tmpDir;
siteUrls;
searchReplaceMap;
Expand All @@ -69,18 +70,20 @@ export class DevEnvSyncSQLCommand {
* @param {string} app The app object
* @param {string} env The environment object
* @param {string} slug The site slug
* @param {Object} lando The lando object
* @param {Function} trackerFn Function to call for tracking
*/
constructor( app, env, slug, trackerFn = () => {} ) {
constructor( app, env, slug, lando, trackerFn = () => {} ) {
this.app = app;
this.env = env;
this.slug = slug;
this.lando = lando;
this.track = trackerFn;
this.tmpDir = makeTempDir();
}

get landoDomain() {
return `${ this.slug }.vipdev.lndo.site`;
return `${ this.slug }.${ this.lando.config.domain }`;
}

get sqlFile() {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/dev-environment/dev-environment-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ export async function handleCLIException(
}
}

const verifyDNSResolution = async ( slug: string ): Promise< void > => {
const verifyDNSResolution = async ( slug: string, domain: string ): Promise< void > => {
const expectedIP = '127.0.0.1';
const testDomain = `${ slug }.vipdev.lndo.site`;
const testDomain = `${ slug }.${ domain }`;
const advice = `Please add following line to hosts file on your system:\n\n${ expectedIP } ${ testDomain }\n\nLearn more: https://docs.wpvip.com/vip-local-development-environment/troubleshooting-dev-env/#h-resolve-networking-configuration-issues\n`;

debug( `Verifying DNS resolution for ${ testDomain }` );
Expand Down Expand Up @@ -151,7 +151,7 @@ export const validateDependencies = async ( lando: Lando, slug: string ) => {

validateDockerInstalled( lando );
if ( slug ) {
await verifyDNSResolution( slug );
await verifyDNSResolution( slug, lando.config.domain ?? 'vipdev.lndo.site' );
}

const duration = new Date().getTime() - now.getTime();
Expand Down

0 comments on commit 87c6646

Please sign in to comment.